package com.xj.api.bussiness.registerLicense.service.impl;

import com.baomidou.mybatisplus.mapper.Condition;
import com.xj.common.bussiness.registerLicense.entity.TbRegisterLicense;
import com.xj.common.bussiness.registerLicense.entity.registerLicenseMould;
import com.xj.common.bussiness.registerLicense.mapper.TbRegisterLicenseMapper;
import com.xj.api.bussiness.registerLicense.service.ITbRegisterLicenseService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.xj.common.bussiness.transferLicense.entity.TbTransferLicense;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Hmemb
 * @since 2018-01-12
 */
@Service
public class TbRegisterLicenseServiceImpl extends ServiceImpl<TbRegisterLicenseMapper, TbRegisterLicense> implements ITbRegisterLicenseService {

    @Autowired
    private TbRegisterLicenseMapper registerLicenseMapper;

    /**
     * <p>
     *    根据上户表的信息查询过户表
     * <p/>
     * @author zhaohai
     * @param registerLicense
     * @return
     */
    @Override
    public TbTransferLicense searchTransferForRegister(TbRegisterLicense registerLicense) {
        List<TbTransferLicense> list= registerLicenseMapper.searchTransferForRegister(registerLicense);
        if(list.size()>1 || list.size()<0){
            return null;
        }
        TbTransferLicense transferLicense = new TbTransferLicense();
        for (TbTransferLicense tl : list) {
            transferLicense = tl;
        }
        return transferLicense;
    }

    @Override
    public List<registerLicenseMould> searchRegisterLicenseList(TbRegisterLicense registerLicense) {
        List<registerLicenseMould>  list= registerLicenseMapper.searchRegisterLicenseList(registerLicense);
        return list;
    }

    @Override
    public TbTransferLicense searchRegisterLicenseAndImg(Integer id) {
        if(registerLicenseMapper.searchRegisterLicenseAndImg(id) != null){
            return registerLicenseMapper.searchRegisterLicenseAndImg(id);
        }
        return null;
    }

    /**
     * 根据设备牌号查询上户表
     * @param plateSubject
     * @return
     */
    @Override
    public TbRegisterLicense searchRegisterLicenseForPlateSubject(String plateSubject) {
        List<TbRegisterLicense> registerLicenseList = registerLicenseMapper.selectList(Condition.create().eq("plate_subject",plateSubject));
        if(registerLicenseList.size()>1 || registerLicenseList.size()<0){
            return null;
        }
        TbRegisterLicense registerLicense = new TbRegisterLicense();
        for (TbRegisterLicense tl : registerLicenseList) {
            registerLicense = tl;
        }
        return registerLicense;
    }
}
